home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / gcc / ixemsdk.lha / man / cat3 / fts.0 < prev    next >
Text File  |  1996-09-02  |  23KB  |  375 lines

  1.  
  2. FTS(3)                     UNIX Programmer's Manual                     FTS(3)
  3.  
  4. NNAAMMEE
  5.      ffttss - traverse a file hierarchy
  6.  
  7. SSYYNNOOPPSSIISS
  8.      ##iinncclluuddee <<ssyyss//ttyyppeess..hh>>
  9.      ##iinncclluuddee <<ssyyss//ssttaatt..hh>>
  10.      ##iinncclluuddee <<ffttss..hh>>
  11.  
  12.      _F_T_S _*
  13.      ffttss__ooppeenn(_c_h_a_r _* _c_o_n_s_t _*_p_a_t_h___a_r_g_v, _i_n_t _o_p_t_i_o_n_s,
  14.              _i_n_t _*_c_o_m_p_a_r_(_c_o_n_s_t _F_T_S_E_N_T _*_*_, _c_o_n_s_t _F_T_S_E_N_T _*_*_))
  15.  
  16.      _F_T_S_E_N_T _*
  17.      ffttss__rreeaadd(_F_T_S _*_f_t_s_p)
  18.  
  19.      _F_T_S_E_N_T _*
  20.      ffttss__cchhiillddrreenn(_F_T_S _*_f_t_s_p, _i_n_t _o_p_t_i_o_n_s)
  21.  
  22.      _i_n_t
  23.      ffttss__sseett(_F_T_S _f_t_s_p, _F_T_S_E_N_T _*_f, _i_n_t _o_p_t_i_o_n_s)
  24.  
  25.      _i_n_t
  26.      ffttss__cclloossee(_F_T_S _*_f_t_s_p)
  27.  
  28. DDEESSCCRRIIPPTTIIOONN
  29.      The ffttss functions are provided for traversing UNIX file hierarchies.  A
  30.      simple overview is that the ffttss__ooppeenn() function returns a ``handle'' on a
  31.      file hierarchy, which is then supplied to the other ffttss functions.  The
  32.      function ffttss__rreeaadd() returns a pointer to a structure describing one of
  33.      the files in the file hierarchy.  The function ffttss__cchhiillddrreenn() returns a
  34.      pointer to a linked list of structures, each of which describes one of
  35.      the files contained in a directory in the hierarchy.  In general, direc-
  36.      tories are visited two distinguishable times; in pre-order (before any of
  37.      their descendants are visited) and in post-order (after all of their de-
  38.      scendants have been visited).  Files are visited once.  It is possible to
  39.      walk the hierarchy ``logically'' (ignoring symbolic links) or physically
  40.      (visiting symbolic links), order the walk of the hierarchy or prune
  41.      and/or re-visit portions of the hierarchy.
  42.  
  43.      Two structures are defined (and typedef'd) in the include file <_f_t_s_._h>.
  44.      The first is _F_T_S, the structure that represents the file hierarchy it-
  45.      self.  The second is _F_T_S_E_N_T, the structure that represents a file in the
  46.      file hierarchy.  Normally, an _F_T_S_E_N_T structure is returned for every file
  47.      in the file hierarchy.  In this manual page, ``file'' and ``_F_T_S_E_N_T
  48.      structure'' are generally interchangeable.  The _F_T_S_E_N_T structure contains
  49.      at least the following fields, which are described in greater detail be-
  50.      low:
  51.  
  52.      typedef struct _ftsent {
  53.              u_short fts_info;               /* flags for FTSENT structure */
  54.              char *fts_accpath;              /* access path */
  55.              char *fts_path;                 /* root path */
  56.              short fts_pathlen;              /* strlen(fts_path) */
  57.              char *fts_name;                 /* file name */
  58.              short fts_namelen;              /* strlen(fts_name) */
  59.              short fts_level;                /* depth (-1 to N) */
  60.              int fts_errno;                  /* file errno */
  61.              long fts_number;                /* local numeric value */
  62.              void *fts_pointer;              /* local address value */
  63.              struct ftsent *fts_parent;      /* parent directory */
  64.              struct ftsent *fts_link;        /* next file structure */
  65.              struct ftsent *fts_cycle;       /* cycle structure */
  66.              struct stat *fts_statp;         /* stat(2) information */
  67.      } FTSENT;
  68.  
  69.      These fields are defined as follows:
  70.  
  71.      _f_t_s___i_n_f_o     One of the following flags describing the returned _F_T_S_E_N_T
  72.                   structure and the file it represents.  With the exception of
  73.                   directories without errors (FTS_D), all of these entries are
  74.                   terminal, that is, they will not be revisited, nor will any
  75.                   of their descendants be visited.
  76.  
  77.                   FTS_D        A directory being visited in pre-order.
  78.  
  79.                   FTS_DC       A directory that causes a cycle in the tree.
  80.                                (The _f_t_s___c_y_c_l_e field of the _F_T_S_E_N_T structure
  81.                                will be filled in as well.)
  82.  
  83.                   FTS_DEFAULT  Any _F_T_S_E_N_T structure that represents a file
  84.                                type not explicitly described by one of the
  85.                                other _f_t_s___i_n_f_o values.
  86.  
  87.                   FTS_DNR      A directory which cannot be read.  This is an
  88.                                error return, and the _f_t_s___e_r_r_n_o field will be
  89.                                set to indicate what caused the error.
  90.  
  91.                   FTS_DOT      A file named `.' or `..' which was not speci-
  92.                                fied as a file name to ffttss__ooppeenn() (see
  93.                                FTS_SEEDOT).
  94.  
  95.                   FTS_DP       A directory being visited in post-order.  The
  96.                                contents of the _F_T_S_E_N_T structure will be un-
  97.                                changed from when it was returned in pre-order,
  98.                                i.e. with the _f_t_s___i_n_f_o field set to FTS_D.
  99.  
  100.                   FTS_ERR      This is an error return, and the _f_t_s___e_r_r_n_o
  101.                                field will be set to indicate what caused the
  102.                                error.
  103.  
  104.                   FTS_F        A regular file.
  105.  
  106.                   FTS_NS       A file for which no stat(2) information was
  107.                                available.  The contents of the _f_t_s___s_t_a_t_p field
  108.                                are undefined.  This is an error return, and
  109.                                the _f_t_s___e_r_r_n_o field will be set to indicate
  110.                                what caused the error.
  111.  
  112.                   FTS_NSOK     A file for which no stat(2) information was re-
  113.                                quested.  The contents of the _f_t_s___s_t_a_t_p field
  114.                                are undefined.
  115.  
  116.                   FTS_SL       A symbolic link.
  117.  
  118.                   FTS_SLNONE   A symbolic link with a non-existent target.
  119.                                The contents of the _f_t_s___s_t_a_t_p field reference
  120.                                the file characteristic information for the
  121.                                symbolic link itself.
  122.  
  123.      _f_t_s___a_c_c_p_a_t_h  A path for accessing the file from the current directory.
  124.  
  125.      _f_t_s___p_a_t_h     The path for the file relative to the root of the traversal.
  126.                   This path contains the path specified to ffttss__ooppeenn() as a
  127.                   prefix.
  128.  
  129.      _f_t_s___p_a_t_h_l_e_n  The length of the string referenced by _f_t_s___p_a_t_h.
  130.  
  131.  
  132.      _f_t_s___n_a_m_e     The name of the file.
  133.  
  134.      _f_t_s___n_a_m_e_l_e_n  The length of the string referenced by _f_t_s___n_a_m_e.
  135.  
  136.      _f_t_s___l_e_v_e_l    The depth of the traversal, numbered from -1 to N, where
  137.                   this file was found.  The _F_T_S_E_N_T structure representing the
  138.                   parent of the starting point (or root) of the traversal is
  139.                   numbered -1, and the _F_T_S_E_N_T structure for the root itself is
  140.                   numbered 0.
  141.  
  142.      _f_t_s___e_r_r_n_o    Upon return of a _F_T_S_E_N_T structure from the ffttss__cchhiillddrreenn() or
  143.                   ffttss__rreeaadd() functions, with its _f_t_s___i_n_f_o field set to
  144.                   FTS_DNR, FTS_ERR or FTS_NS, the _f_t_s___e_r_r_n_o field contains the
  145.                   value of the external variable _e_r_r_n_o specifying the cause of
  146.                   the error.  Otherwise, the contents of the _f_t_s___e_r_r_n_o field
  147.                   are undefined.
  148.  
  149.      _f_t_s___n_u_m_b_e_r   This field is provided for the use of the application pro-
  150.                   gram and is not modified by the ffttss functions.  It is ini-
  151.                   tialized to 0.
  152.  
  153.      _f_t_s___p_o_i_n_t_e_r  This field is provided for the use of the application pro-
  154.                   gram and is not modified by the ffttss functions.  It is ini-
  155.                   tialized to NULL.
  156.  
  157.      _f_t_s___p_a_r_e_n_t   A pointer to the _F_T_S_E_N_T structure referencing the file in
  158.                   the hierarchy immediately above the current file, i.e. the
  159.                   directory of which this file is a member.  A parent struc-
  160.                   ture for the initial entry point is provided as well, howev-
  161.                   er, only the _f_t_s___l_e_v_e_l, _f_t_s___n_u_m_b_e_r and _f_t_s___p_o_i_n_t_e_r fields
  162.                   are guaranteed to be initialized.
  163.  
  164.      _f_t_s___l_i_n_k     Upon return from the ffttss__cchhiillddrreenn() function, the _f_t_s___l_i_n_k
  165.                   field points to the next structure in the NULL-terminated
  166.                   linked list of directory members.  Otherwise, the contents
  167.                   of the _f_t_s___l_i_n_k field are undefined.
  168.  
  169.      _f_t_s___c_y_c_l_e    If a directory causes a cycle in the hierarchy (see FTS_DC),
  170.                   either because of a hard link between two directories, or a
  171.                   symbolic link pointing to a directory, the _f_t_s___c_y_c_l_e field
  172.                   of the structure will point to the _F_T_S_E_N_T structure in the
  173.                   hierarchy that references the same file as the current
  174.                   _F_T_S_E_N_T structure.  Otherwise, the contents of the _f_t_s___c_y_c_l_e
  175.                   field are undefined.
  176.  
  177.      _f_t_s___s_t_a_t_p    A pointer to stat(2) information for the file.
  178.  
  179.      A single buffer is used for all of the paths of all of the files in the
  180.      file hierarchy.  Therefore, the _f_t_s___p_a_t_h and _f_t_s___a_c_c_p_a_t_h fields are guar-
  181.      anteed to be NULL-terminated _o_n_l_y for the file most recently returned by
  182.      ffttss__rreeaadd().  To use these fields to reference any files represented by
  183.      other _F_T_S_E_N_T structures will require that the path buffer be modified us-
  184.      ing the information contained in that _F_T_S_E_N_T structure's _f_t_s___p_a_t_h_l_e_n
  185.      field.  Any such modifications should be undone before further calls to
  186.      ffttss__rreeaadd() are attempted.  The _f_t_s___n_a_m_e field is always NULL-terminated.
  187.  
  188. FFTTSS__OOPPEENN
  189.      The ffttss__ooppeenn() function takes a pointer to an array of character pointers
  190.      naming one or more paths which make up a logical file hierarchy to be
  191.      traversed.  The array must be terminated by a NULL pointer.
  192.  
  193.      There are a number of options, at least one of which (either FTS_LOGICAL
  194.      or FTS_PHYSICAL) must be specified.  The options are selected by _o_r'ing
  195.      the following values:
  196.  
  197.      FTS_COMFOLLOW
  198.                    This option causes any symbolic link specified as a root
  199.                    path to be followed immediately whether or not FTS_LOGICAL
  200.                    is also specified.
  201.  
  202.      FTS_LOGICAL   This option causes the ffttss routines to return _F_T_S_E_N_T struc-
  203.                    tures for the targets of symbolic links instead of the sym-
  204.                    bolic links themselves.  If this option is set, the only
  205.                    symbolic links for which _F_T_S_E_N_T structures are returned to
  206.                    the application are those referencing non-existent files.
  207.                    Either FTS_LOGICAL or FTS_PHYSICAL _m_u_s_t be provided to the
  208.                    ffttss__ooppeenn() function.
  209.  
  210.      FTS_NOCHDIR   As a performance optimization, the ffttss functions change di-
  211.                    rectories as they walk the file hierarchy.  This has the
  212.                    side-effect that an application cannot rely on being in any
  213.                    particular directory during the traversal.  The FTS_NOCHDIR
  214.                    option turns off this optimization, and the ffttss functions
  215.                    will not change the current directory.  Note that applica-
  216.                    tions should not themselves change their current directory
  217.                    and try to access files unless FTS_NOCHDIR is specified and
  218.                    absolute pathnames were provided as arguments to
  219.                    ffttss__ooppeenn().
  220.  
  221.      FTS_NOSTAT    By default, returned _F_T_S_E_N_T structures reference file char-
  222.                    acteristic information (the _s_t_a_t_p field) for each file vis-
  223.                    ited.  This option relaxes that requirement as a perfor-
  224.                    mance optimization, allowing the ffttss functions to set the
  225.                    _f_t_s___i_n_f_o field to FTS_NSOK and leave the contents of the
  226.                    _s_t_a_t_p field undefined.
  227.  
  228.      FTS_PHYSICAL  This option causes the ffttss routines to return _F_T_S_E_N_T struc-
  229.                    tures for symbolic links themselves instead of the target
  230.                    files they point to.  If this option is set, _F_T_S_E_N_T struc-
  231.                    tures for all symbolic links in the hierarchy are returned
  232.                    to the application.  Either FTS_LOGICAL or FTS_PHYSICAL
  233.                    _m_u_s_t be provided to the ffttss__ooppeenn() function.
  234.  
  235.      FTS_SEEDOT    By default, unless they are specified as path arguments to
  236.                    ffttss__ooppeenn(), any files named `.' or `..' encountered in the
  237.                    file hierarchy are ignored.  This option causes the ffttss
  238.                    routines to return _F_T_S_E_N_T structures for them.
  239.  
  240.      FTS_XDEV      This option prevents ffttss from descending into directories
  241.                    that have a different device number than the file from
  242.                    which the descent began.
  243.  
  244.      The argument ccoommppaarr() specifies a user-defined function which may be used
  245.      to order the traversal of the hierarchy.  It takes two pointers to point-
  246.      ers to _F_T_S_E_N_T structures as arguments and should return a negative value,
  247.      zero, or a positive value to indicate if the file referenced by its first
  248.      argument comes before, in any order with respect to, or after, the file
  249.      referenced by its second argument.  The _f_t_s___a_c_c_p_a_t_h, _f_t_s___p_a_t_h and
  250.      _f_t_s___p_a_t_h_l_e_n fields of the _F_T_S_E_N_T structures may _n_e_v_e_r be used in this
  251.      comparison.  If the _f_t_s___i_n_f_o field is set to FTS_NS or FTS_NSOK, the
  252.      _f_t_s___s_t_a_t_p field may not either.  If the ccoommppaarr() argument is NULL, the
  253.      directory traversal order is in the order listed in _p_a_t_h___a_r_g_v for the
  254.      root paths, and in the order listed in the directory for everything else.
  255.  
  256. FFTTSS__RREEAADD
  257.      The ffttss__rreeaadd() function returns a pointer to an _F_T_S_E_N_T structure describ-
  258.      ing a file in the hierarchy.  Directories (that are readable and do not
  259.      cause cycles) are visited at least twice, once in pre-order and once in
  260.      post-order.  All other files are visited at least once.  (Hard links be-
  261.      tween directories that do not cause cycles or symbolic links to symbolic
  262.      links may cause files to be visited more than once, or directories more
  263.      than twice.)
  264.  
  265.      If all the members of the hierarchy have been returned, ffttss__rreeaadd() re-
  266.      turns NULL and sets the external variable _e_r_r_n_o to 0.  If an error unre-
  267.      lated to a file in the hierarchy occurs, ffttss__rreeaadd() returns NULL and sets
  268.      _e_r_r_n_o appropriately.  If an error related to a returned file occurs, a
  269.      pointer to an _F_T_S_E_N_T structure is returned, and _e_r_r_n_o may or may not have
  270.      been set (see _f_t_s___i_n_f_o).
  271.  
  272.      The _F_T_S_E_N_T structures returned by ffttss__rreeaadd() may be overwritten after a
  273.      call to ffttss__cclloossee() on the same file hierarchy stream, or, after a call
  274.      to ffttss__rreeaadd() on the same file hierarchy stream unless they represent a
  275.      file of type directory, in which case they will not be overwritten until
  276.      after a call to ffttss__rreeaadd() after the _F_T_S_E_N_T structure has been returned
  277.      by the function ffttss__rreeaadd() in post-order.
  278.  
  279. FFTTSS__CCHHIILLDDRREENN
  280.      The ffttss__cchhiillddrreenn() function returns a pointer to an _F_T_S_E_N_T structure de-
  281.      scribing the first entry in a NULL-terminated linked list of the files in
  282.      the directory represented by the _F_T_S_E_N_T structure most recently returned
  283.      by ffttss__rreeaadd().  The list is linked through the _f_t_s___l_i_n_k field of the
  284.      _F_T_S_E_N_T structure, and is ordered by the user-specified comparison func-
  285.      tion, if any.  Repeated calls to ffttss__cchhiillddrreenn() will recreate this linked
  286.      list.
  287.  
  288.      As a special case, if ffttss__rreeaadd() has not yet been called for a hierarchy,
  289.      ffttss__cchhiillddrreenn() will return a pointer to the files in the logical directo-
  290.      ry specified to ffttss__ooppeenn(), i.e. the arguments specified to ffttss__ooppeenn().
  291.      Otherwise, if the _F_T_S_E_N_T structure most recently returned by ffttss__rreeaadd()
  292.      is not a directory being visited in pre-order, or the directory does not
  293.      contain any files, ffttss__cchhiillddrreenn() returns NULL and sets _e_r_r_n_o to zero.
  294.      If an error occurs, ffttss__cchhiillddrreenn() returns NULL and sets _e_r_r_n_o appropri-
  295.      ately.
  296.  
  297.      The _F_T_S_E_N_T structures returned by ffttss__cchhiillddrreenn() may be overwritten after
  298.      a call to ffttss__cchhiillddrreenn(), ffttss__cclloossee() or ffttss__rreeaadd() on the same file hi-
  299.      erarchy stream.
  300.  
  301.      _O_p_t_i_o_n may be set to the following value:
  302.  
  303.      FTS_NAMEONLY  Only the names of the files are needed.  The contents of
  304.                    all the fields in the returned linked list of structures
  305.                    are undefined with the exception of the _f_t_s___n_a_m_e and
  306.                    _f_t_s___n_a_m_e_l_e_n fields.
  307.  
  308. FFTTSS__SSEETT
  309.      The function ffttss__sseett() allows the user application to determine further
  310.      processing for the file _f of the stream _f_t_s_p. The ffttss__sseett() function re-
  311.      turns 0 on success, and -1 if an error occurs.  _O_p_t_i_o_n must be set to one
  312.      of the following values:
  313.  
  314.      FTS_AGAIN     Re-visit the file; any file type may be re-visited.  The
  315.                    next call to ffttss__rreeaadd() will return the referenced file.
  316.                    The _f_t_s___s_t_a_t and _f_t_s___i_n_f_o fields of the structure will be
  317.                    reinitialized at that time, but no other fields will have
  318.                    been changed.  This option is meaningful only for the most
  319.                    recently returned file from ffttss__rreeaadd().  Normal use is for
  320.                    post-order directory visits, where it causes the directory
  321.                    to be re-visited (in both pre and post-order) as well as
  322.                    all of its descendants.
  323.  
  324.      FTS_FOLLOW    The referenced file must be a symbolic link.  If the refer-
  325.                    enced file is the one most recently returned by ffttss__rreeaadd(),
  326.                    the next call to ffttss__rreeaadd() returns the file with the
  327.                    _f_t_s___i_n_f_o and _f_t_s___s_t_a_t_p fields reinitialized to reflect the
  328.                    target of the symbolic link instead of the symbolic link
  329.                    itself.  If the file is one of those most recently returned
  330.                    by ffttss__cchhiillddrreenn(), the _f_t_s___i_n_f_o and _f_t_s___s_t_a_t_p fields of the
  331.                    structure, when returned by ffttss__rreeaadd(), will reflect the
  332.                    target of the symbolic link instead of the symbolic link
  333.                    itself.  In either case, if the target of the symbolic link
  334.                    does not exist the fields of the returned structure will be
  335.                    unchanged and the _f_t_s___i_n_f_o field will be set to FTS_SLNONE.
  336.  
  337.                    If the target of the link is a directory, the pre-order re-
  338.                    turn, followed by the return of all of its descendants,
  339.                    followed by a post-order return, is done.
  340.  
  341.      FTS_SKIP      No descendants of this file are visited.  The file may be
  342.                    one of those most recently returned by either
  343.                    ffttss__cchhiillddrreenn() or ffttss__rreeaadd().
  344.  
  345. FFTTSS__CCLLOOSSEE
  346.      The ffttss__cclloossee() function closes a file hierarchy stream _f_t_s_p and restores
  347.      the current directory to the directory from which ffttss__ooppeenn() was called
  348.      to open _f_t_s_p. The ffttss__cclloossee() function returns 0 on success, and -1 if an
  349.      error occurs.
  350.  
  351. EERRRROORRSS
  352.      The function ffttss__ooppeenn() may fail and set _e_r_r_n_o for any of the errors
  353.      specified for the library functions open(2) and malloc(3).
  354.  
  355.      The function ffttss__cclloossee() may fail and set _e_r_r_n_o for any of the errors
  356.      specified for the library functions chdir(2) and close(2).
  357.  
  358.      The functions ffttss__rreeaadd() and ffttss__cchhiillddrreenn() may fail and set _e_r_r_n_o for
  359.      any of the errors specified for the library functions chdir(2),
  360.      malloc(3),  opendir(3),  readdir(3) and stat(2).
  361.  
  362.      In addition, ffttss__cchhiillddrreenn(), ffttss__ooppeenn() and ffttss__sseett() may fail and set
  363.      _e_r_r_n_o as follows:
  364.  
  365.      [EINVAL]      The options were invalid.
  366.  
  367. SSEEEE AALLSSOO
  368.      find(1),  chdir(2),  stat(2),  qsort(3)
  369.  
  370. SSTTAANNDDAARRDDSS
  371.      The ffttss utility is expected to be included in a future IEEE
  372.      Std1003.1-1988 (``POSIX'') revision.
  373.  
  374. BSD Experimental                April 16, 1994                               6
  375.